<template>
<div>
    <optionkey></optionkey>
    <Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
        <FormItem prop="amount">
            <!-- <Icon type="logo-yen"></Icon> -->
            <!-- <InputNumber :style="{width:'200px'}" v-model="formInline.amount" placeholder="投资金额" ></InputNumber> -->
            <Input type="number" v-model="formInline.amount" placeholder="投资金额">
                <Icon type="logo-yen" slot="prepend"></Icon>
            </Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="handleSubmit('formInline')">保存</Button>
        </FormItem>
    </Form>
    <Button @click="fillAmount(1)">1万</Button>
    <Button @click="fillAmount(5)">5万</Button>
    <Button @click="fillAmount(10)">10万</Button>
    <Button @click="fillAmount(100)">100万</Button>
    
</div>
    
</template>
<script>
import {assets_update} from '@/api/api'
import optionkey from'./optionkey.vue'
    export default {
        components:{
      
      optionkey
    },
        data () {
            return {
                formInline: {
                    amount: this.$store.state.total_assets,
                },
                ruleInline: {
                    amount: [
                        { required: true, message: '请输入投资金额'}
                    ]
                }
            }
        },
        methods: {
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.assets_update()
                    }
                })
            },
            fillAmount(data) {
                this.formInline.amount = data * 10000
            },
            assets_update() {
                let data = {
                    "total_assets":this.formInline.amount,
                    "account_id": window.localStorage.account_id
                }

              assets_update(data)
              .then (res => {
                  if (res.code == 0) {
                      this.$store.commit('setRecommendCurStep',2)
                      if (this.$store.state.recommendStep < 2) {
                          this.$store.commit('setRecommendStep',2)
                      }
                    //   window.localStorage.setItem('total_assets',this.formInline.amount)
                      this.$store.commit('setTotal_assets', this.formInline.amount)
                      
                    this.$Message.success('保存成功!');
                  } else {
                    this.$Message.error('保存失败!');
                  }

              })
              .catch(err => {
                  this.$Message.error(err);
              })
                
            }
        }
    }
</script>
